<%
	Session("FormName")="F29"
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<META content=no-cache http-equiv=Pragma>
<META content=no-cache http-equiv=Cache-Control>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<!--#include file="CVUnicode.inc"-->
<!--#include file=..\vbFunction.inc-->
</head>
<body bgcolor="#F8F9D9">
<%
  On Error resume next
  Server.ScriptTimeOut =20
  Dim bArray()
  function Subst (strValue, strOldValue, strNewValue)
    intLoc = InStr(strValue, strOldValue)
    While intLoc > 0
      if intLoc > 1 then
        if intLoc = Len(strValue) then
          strValue = Left(strValue, intLoc-1) & strNewValue
        else
          strValue = Left(strValue, intLoc -1) & strNewValue & Right(strValue, Len(strValue)-(intLoc-Len(strOldValue)+1))
        end if
      else
        strValue = strNewValue & Right(strValue, Len(strValue)-1)
      end if
      intLoc = InStr(strValue, strOldValue)
    Wend
    Subst = strValue
  end function

  function FixUpItems (strItem)
    if strItem <> "" then
      strItem = Subst(strItem, "<", "&lt;")
      strItem = Subst(strItem, ">", "&gt;")
      FixUpItems = strItem
    else
      FixUpItems = "<br>"
    end if
  end function

  rem ******************************************
  rem * Shows a form for the user to fill in
  rem *  host, uid and pwd.
  rem ******************************************
  
  sub ShowPopForm (strHostName, strUser, strPassword)
    Response.Write "<table border=0>"
    Response.Write "<form action=""OpenOtherSite.asp"" method=post>"
    Response.Write "<tr><td>Enter POP3 Mail Host:<td><input type=text size=45 name=host value=""" & strHostName & """>"
    Response.Write "<tr><td>Enter POP3 User Name:<td><input type=text size=45 name=uid value=""" & strUser & """>"
    Response.Write "<tr><td>Enter POP3 Password:<td><input type=password size=45 name=pwd value=""" & strPassword & """>"
    Response.Write "<input type=""Submit"">"
    Response.Write "</form>"
    Response.Write "</table>"

  end sub

  rem ******************************************
  rem * Get the list of all message headers and
  rem *  display the info to the client
  rem ******************************************
  
  sub ShowMessageList (strHost, strUid, strPwd)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")
    Mailer.RemoteHost  = strHost
    Mailer.UserName = strUid
    Mailer.Password = strPwd
   Response.Write "<p align=center><B>&#272;&#258;NG KÝ CÔNG V&#258;N &#272;&#7870;N T&#7914; <font color=blue>CÁC ĐƠN VỊ THÀNH VIÊN</font></B>"	    
    if Mailer.GetPopHeaders then
      Response.Write "<table border=0 width=""100%"" style='BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;Border-color:#C0C0C0'>" & VbCrLf
	 Response.Write "<form name=""frmDangky"" method=post>"      
      Response.Write "<tr bgcolor=#173584>" & VbCrLf
      Response.Write "<td width=% align=center  bgcolor=#BDD5D0><b>STT</b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Trích yếu" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Ngày gi&#7901;" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Nơi gửi" & "<b></td>" & VbCrLf
      'Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Ghi chú" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Kích th&#432;&#7899;c" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Xoá" & "<b></td>" & VbCrLf
      Response.Write "</tr>" & VbCrLf

      varArray = Mailer.MessageInfo
      if VarType(varArray) <> vbNull And IsEmpty(varArray) <>  True then
        ArrayLimit = UBound(varArray)
        'For I = 0 to ArrayLimit
		For I = ArrayLimit to 0 step -1
	        if (i/2=int(i/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if

          Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"          
          strMsgNo = Trim(varArray(I)(0))
		  mSTT = ArrayLimit-I+1

          rem the random number is to prevent the browser from thinking that the
          rem   page is cached when you try and delete the same message number
          Randomize
          intRndNo = Int(500 * Rnd)
          'Response.Write "<td >" & strMsgNo & "</td>"
		Response.Write "<td align=center>" & mSTT  & "</td>"		  

          strSubject = varArray(I)(1)
          if strSubject = "" then strSubject = "(No Subject)"
          
	     'bSubject=VietCodeToUnicode(bArray,FixUpItems (strSubject))

		bSubject=strSubject				
		'bSubject=replace(strSubject,"#",">")		
		bSubject=Session("ClsFun").giaima(bSubject)		
	
		bSubject=FixUpItems (bSubject)		
		
		if funTieudeCorrect(bSubject) then
			Call  SubTieude(bCQBH,bTieude,bSubject)
		else
			bCQBH= FixUpItems (varArray(I)(3)) 
			bTieude=bSubject
		end if		

          Response.Write "<td align=left>" & "<a href=OpenOtherSite.asp?msgno=" & strMsgNo & "&rndno=" & intRndNo & ">" & bTieude & "</a></td>" & VbCrLf

		Response.Write "<td align=left>" & FormatNgayGio(varArray(I)(2)) & "</td>" & VbCrLf
		
		'Noi gui	

		Response.Write "<td>" & bCQBH
		bEmail=SubLayEmail(FixUpItems (varArray(I)(3)))
		If not DonViExist(bEmail) then 
			Response.Write "<input name=Dangky type=button value='Đăng ký' style='font-family: Arial;height:20;font-size:8pt;' onclick='return Dangky_onclick("""& bCQBH &""","""& bEmail &""")'>"
		End if
		Response.Write "</td>" & VbCrLf         
		
		'Ghi chu
          'Response.Write "<td align=left>" & bGhichu & "</td>" & VbCrLf

          rem skip the sender field for this demo
          rem Response.Write "<td align=left>" & FixUpItems (varArray(I)(4)) & "</td>" & VbCrLf

          rem skip the to field for this demo
          rem Response.Write "<td align=left>" & FixUpItems (varArray(I)(5)) & "</td>" & VbCrLf

          rem skip the reply-to field for the demo
          rem Response.Write "<td align=left>" & FixUpItems (varArray(I)(6)) & "</td>"

          Response.Write "<td align=left>" & varArray(I)(7) & "</td>"

          Response.Write "<td align=left>" & "<a href=OpenOtherSite.asp?deletemsg=" & strMsgNo & "&rndno=" & intRndNo & ">Xoá</a></td>"
          Response.Write "</tr>" & Chr(10) & Chr(13)
        Next
      else
        Response.Write "<tr><td colspan=10 align=center><b>No messages on server</b></tr>"
      end if
      Response.Write "</form>"
      Response.Write "</table><center><p><br>"
      Response.Write "<a href=""OpenOtherSite.asp?rndno=" & intRndNo & """>Refresh</a></center>"
    else
      Response.Write "<p>Connection Failure. Check your mailhost, username and password."
    end if
    Response.Write "</blockquote>"
  end sub

  rem ******************************************
  rem * Shows the text for one specific message
  rem ******************************************
  sub ShowMessage(strHost, strUid, strPwd, strMsgNo)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")
    strMailBaseDir =server.MapPath("..\Xuly\temp")
    Mailer.MailDirectory = strMailBaseDir
    Mailer.RemoteHost = strHost
    Mailer.UserName   = strUid
    Mailer.Password   = strPwd
    Mailer.OpenPop3
    Mailer.Pop3Log = "c:\pop3log.txt"
    Mailer.Retrieve strMsgNo
    Mailer.ClosePop3
    'bBody=VietCodeToUnicode(bArray,Mailer.BodyText)
    'bSubject=VietCodeToUnicode(bArray,FixUpItems(Mailer.Subject))    
	
	bBody=Mailer.BodyText		
	bBody=replace(bBody,Chr(13),"")
	bBody=replace(bBody,Chr(10),"")

	bBody=Session("ClsFun").giaima(bBody)	
	
	bSubject=Mailer.Subject
	bSubject=replace(bSubject,Chr(13),"")
	bSubject=replace(bSubject,Chr(10),"")

	bSubject=Session("ClsFun").giaima(bSubject)		
	bSubject=FixUpItems(bSubject)
	
	on error resume next		       
	
	if funTieudeCorrect(bSubject) then
		Session("tenvtden")="frmdsvtden.asp"
		Call SubTieude(bCQBH,bTieude,bSubject)
		Call SubNoidung(bNguoiky,bNgayky,bSokyhieu,bTrichyeu,bGhichu,bNoidung,bBody)
    
		Response.Write "<form name=frm method=post action='frmvtden.asp?bComm=add&bSendfrom=mail&MsgNo="& strMsgNo &"'>"    
		Response.Write "<textarea name=TxtBody style='visibility:hidden;position:absolute;top:0px;left:0px'>"&  bNoidung &"</textarea>"
		Response.Write "<input name=TxtSubject type=hidden value='"& bTrichyeu &"'>"
		Response.Write "<input name=TxtNguoiky type=hidden value='"& bNguoiky &"'>"
		Response.Write "<input name=TxtNgayky type=hidden value='"& bNgayky &"'>"
		Response.Write "<input name=TxtSokyhieu type=hidden value='"& bSokyhieu &"'>"    
		Response.Write "<input name=TxtCQBH type=hidden value='"& bCQBH &"'>"
			
		Response.Write "<table border=0 width=""100%"" style='BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;Border-color:#C0C0C0'>" & VbCrLf    
		Response.Write "<tr bgcolor=#173584>" & VbCrLf
		Response.Write "<td align=center  bgcolor=#BDD5D0 colspan=2><b>" & "Thông tin chi tiết" & "<b></td>" & VbCrL    
		Response.Write  "</tr>"       

		color="#eeeecc"
		Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"       
		
		Call writeText("Người ký")    
		
		Response.Write  "<td>"
		Response.Write bNguoiky
		Response.Write  "</td>"    
		
		Response.Write  "</tr>"

		Response.Write  "<tr>"
		
		Call writeText("Ngày ký")    
		   
		Response.Write  "<td>"
		Response.Write bNgayky
		Response.Write  "</td>"
		
		Response.Write  "</tr>"

		color="#eeeecc"
		Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"       
		
		Call writeText("Số ký hiệu")    

		Response.Write  "<td>"
		Response.Write bSokyhieu
		Response.Write  "</td>"

		Response.Write  "</tr>"        

		Response.Write  "<tr>"

		Call writeText("Cơ quan ban hành")    
		
		Response.Write  "<td>"
		Response.Write bCQBH
		Response.Write  "</td>"

		Response.Write  "</tr>"     

		color="#eeeecc"
		Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"       
		
		Call writeText("Trích yếu")    
		
		Response.Write  "<td>"
		Response.Write bTrichyeu
		Response.Write  "</td>"
		
		Response.Write  "</tr>"                

		Response.Write  "<tr>"
		
		Call writeText("Ghi chú")    
		
		Response.Write  "<td>"
		Response.Write bGhichu
		Response.Write  "</td>"
		
		Response.Write  "</tr>"                

		Response.Write  "</table>"
		'Response.Write "<p align=center>"
		Response.Write "<center>"
		Response.Write "<input name=CmdOK type=submit value='&#272;&#259;ng ký công v&#259;n &#273;&#7871;n t&#7915; đơn vị' style='font-family: Arial;'>"
		Response.Write "</center>"


		if Mailer.AttachmentCount > 0 then
		  'Response.Write "<table border=1 width=""100%"">" & VbCrLf
		  'Response.Write "<tr><td>Tệp gắn kèm</td><td>Kiểu</td><td>Tên</td><td>Kích thước</td></tr>" & VbCrLf

		  'Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Nội dung" & "<b></td>" & VbCrL          
		  
		  Response.Write "<table border=0 width=""100%"" style='BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;Border-color:#C0C0C0'>" & VbCrLf          
		 Response.Write "<tr bgcolor=#BDD5D0>" & VbCrLf
		  Response.Write "<td align=center><b>" & "Tệp gắn kèm" & "<b></td>"
		  'Response.Write "<td align=center><b>" & "Kiểu" & "<b></td>"
		  Response.Write "<td align=center><b>" & "Tên" & "<b></td>"
		  Response.Write "<td align=center><b>" & "Kích thước (KB)" & "<b></td>"     

		  Response.Write  "</tr>"       
		  
		  For intCount = 1 to Mailer.AttachmentCount
			if Mailer.GetAttachmentInfo (intCount) then
			
				if (intCount/2=int(intCount/2)) then
					color="#eeeecc"
				else
					color="#F8F9D9"
				end if

			  Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"                  
			  'Response.Write "<td align=center><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & intCount & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttContentType & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileName & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileSize & "</a></td></tr>" & VbCrLf
			Response.Write "<td align=center><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & intCount & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileName & "</a></td><td align=right><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileSize & "</a></td></tr>" & VbCrLf

			  Mailer.SaveAttachment (intCount)
			end if
		  Next
		  Response.Write "</table>" & VbCrLf
		end if
	    Response.Write "</form>"
	
	else	'Tieu de Correct

		Response.Write "<textarea name=TxtBody style='visibility:hidden;position:absolute;top:0px;left:0px'>"&  bNoidung &"</textarea>"
		Response.Write "<table border=0 width=""100%"" style='BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;Border-color:#C0C0C0'>" & VbCrLf    
		Response.Write "<tr bgcolor=#173584>" & VbCrLf
		Response.Write "<td align=center  bgcolor=#BDD5D0 colspan=2><b>" & "Nội dung" & "<b></td>" & VbCrL    
		Response.Write  "</tr>"

		Response.Write  "<tr>"		  
		Response.Write  "<td>"
		Response.Write bBody
		Response.Write  "</td>"
		Response.Write  "</tr>"		

		if Mailer.AttachmentCount > 0 then
		  'Response.Write "<table border=1 width=""100%"">" & VbCrLf
		  'Response.Write "<tr><td>Tệp gắn kèm</td><td>Kiểu</td><td>Tên</td><td>Kích thước</td></tr>" & VbCrLf

		  'Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Nội dung" & "<b></td>" & VbCrL          
		  
		  Response.Write "<table border=0 width=""100%"" style='BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: none;Border-color:#C0C0C0'>" & VbCrLf          
		 Response.Write "<tr bgcolor=#BDD5D0>" & VbCrLf
		  Response.Write "<td align=center><b>" & "Tệp gắn kèm" & "<b></td>"
		  'Response.Write "<td align=center><b>" & "Kiểu" & "<b></td>"
		  Response.Write "<td align=center><b>" & "Tên" & "<b></td>"
		  Response.Write "<td align=center><b>" & "Kích thước (KB)" & "<b></td>"
		  Response.Write  "</tr>"       				  
		  
		  For intCount = 1 to Mailer.AttachmentCount
			if Mailer.GetAttachmentInfo (intCount) then
			
				if (intCount/2=int(intCount/2)) then
					color="#eeeecc"
				else
					color="#F8F9D9"
				end if

			  Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"                  
			  'Response.Write "<td align=center><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & intCount & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttContentType & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileName & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileSize & "</a></td></tr>" & VbCrLf
			Response.Write "<td align=center><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & intCount & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileName & "</a></td><td align=right><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileSize & "</a></td></tr>" & VbCrLf

			  Mailer.SaveAttachment (intCount)
			end if
		  Next
		  Response.Write "</table>" & VbCrLf
		end if
		
	end if
  end sub

  rem ******************************************
  rem * DELETE the message PERMANENTLY from the
  rem *  server
  rem ******************************************
  sub DeleteMessage (strHost, strUid, strPwd, strMsgNo)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")

    Mailer.RemoteHost = strHost
    Mailer.UserName   = strUid
    Mailer.Password   = strPwd
    Mailer.OpenPop3

    rem We could do multiple deletes here but this demo only does 1. You must
    rem  close the server at this point or our message numbers in
    rem  ShowMessageList won't be correct.

    Mailer.Delete strMsgNo
    Mailer.ClosePop3

    ShowMessageList strHost, strUid, strPwd
  end sub
' main 

	bComm=Request("bComm")	
	if bComm="dangky" then
		strCQBH=Request("strCQBH")
		strEmail=Request("strEmail")
	
		sSQL="insert into othersite(ID,TenDonvi,Email) values ('"& TaoMa("ID","OtherSite") &"','"& strCQBH &"','" & strEmail & "')"
		Conn.Execute sSQL
	end if
	
	sSQL="Select * from config"
	Set RecConf=server.createObject("ADODB.Recordset")
	RecConf.cursortype=3
	RecConf.Cachesize=5
	RecConf.open sSQL,Conn
	if RecConf.recordcount then
		Session("hostMail")=recconf("SitePop3IPMail")
		Session("uidMail")=recconf("SiteUsername")
		Session("pwdMail")=recconf("SitePassword")		
	  	strHost       = Session("hostMail")
  		strUid        = Session("uidMail")
		strPwd        = Session("pwdMail")
  		strMsgNo      = Request.QueryString("msgno")
  		strDeleteNo   = Request.QueryString("deletemsg")
  		if (strUid = "") or (strPwd = "") or (strHost = "") then
    			ShowPopForm strHost, strUid, strPwd
  		else
    			if (strMsgNo <> "") then
      			ShowMessage strHost, strUid, strPwd, strMsgNo
    			else
      			if (strDeleteNo <> "") then
        				DeleteMessage strHost, strUid, strPwd, strDeleteNo
      			else
        				ShowMessageList strHost, strUid, strPwd
      			end if    
    			end if
  		end if
  	end if
  	RecConf.Close
  	Set RecConf=nothing
%>

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function Dangky_onclick(strCQBH,strEmail){
var name = confirm("Đăng ký vào danh sách đơn vị thành viên?")
	if (name == true)
	{
		document.frmDangky.action="OpenOtherSite.asp?bComm=dangky&strCQBH="+strCQBH +"&strEmail="+strEmail;
		document.frmDangky.submit();		
	}
}
//-->
</SCRIPT>

<script language=vbscript runat=server>

	Function DonViExist(ByVal bEmail)
		DonViExist=false
		sSQL="select * from othersite where email = '"& bEmail &"'"
		Set RecTemp=server.createObject("ADODB.Recordset")
		RecTemp.cursortype=3
		RecTemp.Cachesize=5
		RecTemp.open sSQL,Conn
		If RecTemp.RecordCount then
			DonViExist=true		
		End if		
		RecTemp.Close
		Set RecTemp=nothing		
	End Function
	
	Function SubLayEmail(ByVal bStr)	    
		strKytu="&lt;"
		'strEnd="&gt;"	    
				
	    posKytu= InStr(1, bStr, strKytu, vbBinaryCompare)
	    
	    lenKytu= Len(bStr) - posKytu- len(strKytu)
	    	    
	    SubLayEmail= Mid(bStr, posKytu+len(strKytu), lenKytu-3) 
	End Function

	Function funTieudeCorrect(bStr)
		funTieudeCorrect=false
		strTieude="tieude:("
	    	    
		if  InStr(1, bStr, strTieude, vbBinaryCompare) then		
			funTieudeCorrect=true
		end if		
	End Function

	Function writeText(mText)
	     Response.Write  "<td width=""15%"">"		
		response.write "<font  size=3 color=black>"	
		response.write "<b>"	
		response.write  mText 
		response.write "</b>"		
		response.write  "</font>"
		Response.Write  "</td>"		
	End Function

	Function SubNoidung(ByRef Nguoiky, ByRef Ngayky, ByRef Sokyhieu, ByRef Trichyeu, ByRef Ghichu, ByRef Noidung, ByVal bStr)
	    On error resume next

	    strNguoiky = "nguoiky:("
	    strNgayky = "ngayky:("
	    strSokyhieu="sokyhieu:("
	    strTrichyeu="trichyeu:("
	    strGhichu="ghichu:("
	    
	    posNguoiky = InStr(1, bStr, strNguoiky, vbBinaryCompare)
	    posNgayky = InStr(posNguoiky, bStr, strNgayky, vbBinaryCompare)
	    posSokyhieu=InStr(posNgayky, bStr, strSokyhieu, vbBinaryCompare)
	    posTrichyeu=InStr(posSokyhieu, bStr, strTrichyeu, vbBinaryCompare)
	    posGhichu=InStr(posTrichyeu, bStr, strGhichu, vbBinaryCompare)

	    lenNguoiky = posNgayky - posNguoiky - Len(strNguoiky) - 2
	    lenNgayky = posSokyhieu - posNgayky - Len(strNgayky)-2
	    lenSokyhieu=posTrichyeu - posSokyhieu - Len(strSokyhieu)-2
	    lenTrichyeu= posGhichu- posTrichyeu - Len(strTrichyeu)-2	    	    
	    lenGhichu=Len(bStr) - posGhichu - Len(strGhichu)-2
	    if lenGhichu < 0 then lenGhichu =0
	    
	    Nguoiky = Mid(bStr, posNguoiky + Len(strNguoiky), lenNguoiky)
	    Ngayky = Mid(bStr, posNgayky + Len(strNgayky), lenNgayky)
	    Sokyhieu = Mid(bStr, posSokyhieu + Len(strSokyhieu), lenSokyhieu)
	    Trichyeu = Mid(bStr, posTrichyeu + Len(strTrichyeu), lenTrichyeu)
	    Ghichu = Mid(bStr, posGhichu + Len(strGhichu), lenGhichu)
	    
	    Noidung= Mid(bStr, 1, posNguoiky - 1)
	End Function
	
	Function SubTieude(ByRef CQBH, ByRef Tieude, ByVal bStr)
	    Dim posTieude,lenTieude
	    On error resume next
	    
	    strTieude="tieude:("
	    
	    posTieude= InStr(1, bStr, strTieude, vbBinaryCompare)
	    
	    lenTieude= Len(bStr) - posTieude - Len(strTieude)
	    	    
	    Tieude = Mid(bStr, posTieude + Len(strTieude), lenTieude)
	    	    
	    CQBH= Mid(bStr, 1, posTieude-1)
	    
	End Function
	
	Function FormatNgayGio(bValue)
		FormatNgayGio=Mid(bValue,6,20)
	End Function

	Function SubNoidung20_8(ByRef Nguoiky, ByRef Ngayky, ByRef Sokyhieu, ByRef Noidung, ByVal bStr)
	    Dim posNguoiky, posNgayky,posSokyhieu,lenNguoiky, lenNgayky,lenSokyhieu
	    On error resume next

	    strNguoiky = "nguoiky:("
	    strNgayky = "ngayky:("
	    strSokyhieu="sokyhieu:("
	    
	    posNguoiky = InStr(1, bStr, strNguoiky, vbBinaryCompare)
	    posNgayky = InStr(posNguoiky, bStr, strNgayky, vbBinaryCompare)
	    posSokyhieu=InStr(posNgayky, bStr, strSokyhieu, vbBinaryCompare)

	    lenNguoiky = posNgayky - posNguoiky - Len(strNguoiky) - 2
	    lenNgayky = posSokyhieu - posNgayky - Len(strNgayky)-2
	    lenSokyhieu=Len(bStr) - posSokyhieu - Len(strSokyhieu)-2
	    
	    Nguoiky = Mid(bStr, posNguoiky + Len(strNguoiky), lenNguoiky)
	    Ngayky = Mid(bStr, posNgayky + Len(strNgayky), lenNgayky)
	    Sokyhieu = Mid(bStr, posSokyhieu + Len(strSokyhieu), lenSokyhieu)
	    Noidung= Mid(bStr, 1, posNguoiky - 1)
	    
	End Function

	Function SubTieudeOld(ByRef CQBH, ByRef Ghichu,ByRef Tieude, ByVal bStr)
	    Dim posCQBH,lenCQBH,posGhichu,lenGhichu
	    On error resume next
	    
	    strCQBH="cqbh:("
	    strGhichu="ghichu:("
	    
	    posCQBH= InStr(1, bStr, strCQBH, vbBinaryCompare)
	    posGhichu= InStr(posCQBH, bStr, strGhichu, vbBinaryCompare)	    
	    
	    lenCQBH= posGhichu- posCQBH - Len(strCQBH)-2
	    lenGhichu= Len(bStr) - posGhichu - Len(strGhichu)
	    	    
	    CQBH = Mid(bStr, posCQBH + Len(strCQBH), lenCQBH)
	    Ghichu= Mid(bStr, posGhichu + Len(strGhichu), lenGhichu)
	    Tieude= Mid(bStr, 1, posCQBH-1)
	    
	End Function
	
	Function Substring_(ByRef Thanhphan, ByRef Diadiem, ByRef Noidung, ByRef Phuongtien, ByVal bStr)
	    Dim bVTTP, bVTDD, bLen1, bLen2
	    bcat1 = "Thành phần:("
	    bcat2 = "Địa điểm:("
	    bcat3="Phương tiện:("
	    bVTTP = InStr(1, bStr, bcat1, vbBinaryCompare)
	    bVTDD = InStr(bVTTP, bStr, bcat2, vbBinaryCompare)
	    bVTPT=InStr(bVTDD, bStr, bcat3, vbBinaryCompare)
	    bLen1 = bVTDD - bVTTP - Len(bcat1) - 2
	    bLen2 = bVTPT - bVTDD - Len(bcat2)-2
	    bLen3=Len(bStr) - bVTPT - Len(bcat3)
	    Thanhphan = Mid(bStr, bVTTP + Len(bcat1), bLen1)
	    Diadiem = Mid(bStr, bVTDD + Len(bcat2), bLen2)
	    Phuongtien = Mid(bStr, bVTPT + Len(bcat3), bLen3)
	    Noidung = Mid(bStr, 1, bVTTP - 1)
	End Function	
</script>
</body>
</html>